package io.renren.modules.frt.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.frt.entity.ProReport4Entity;
import io.renren.modules.frt.service.ProReport4Service;
import io.renren.modules.frt.service.TaskUserService;



/**
 * 表4：专业大户调查表
 *
 * @author qibing.huang
 * @email abingtech@163.com
 * @date 2018-11-25 10:25:33
 */
@RestController
@RequestMapping("frt/proreport4")
public class ProReport4Controller {
    @Autowired
    private ProReport4Service proReport4Service;
    @Autowired
    private TaskUserService taskUserService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("frt:proreport4:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = proReport4Service.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{reportId}")
    public R info(@PathVariable("reportId") Long reportId){
        ProReport4Entity proReport4 = proReport4Service.selectById(reportId);

        return R.ok().put("proreport4", proReport4);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @Transactional
    public R save(@RequestBody ProReport4Entity proReport4){
		
		if(proReport4.getTaskUserId() == null) {
    		return R.error("task_user_id["+proReport4.getTaskUserId()+"]参数错误");
    	}
    	
		proReport4Service.insert(proReport4);
		
		taskUserService.onlineCallbackTaskUser(proReport4.getTaskUserId(), proReport4.getReportId());

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ProReport4Entity proReport4){
		proReport4Service.updateById(proReport4);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("frt:proreport4:delete")
    public R delete(@RequestBody Long[] reportIds){
		proReport4Service.deleteBatchIds(Arrays.asList(reportIds));

        return R.ok();
    }

}
